package com.dao;

import java.util.List;

import com.entity.HyFurniture;
import com.entity.HyFurnitureImage;
import com.entity.HyFurnitureWithImage;
import org.apache.ibatis.annotations.*;

/**
 * 家具列表Mapper接口
 * 
 * @author 白杨
 * @date 2025-02-14
 */
@Mapper
public interface HyFurnitureMapper 
{
    // 增加家具
    @Insert("INSERT INTO hy_furniture(name, description, furnnum, price, region_id, lease_price, material, size, manufacturer, category_id, created_at, updated_at) " +
            "VALUES(#{name}, #{description}, #{furnnum}, #{price}, #{region_id}, #{lease_price}, #{material}, #{size}, #{manufacturer}, #{category_id}, NOW(), NOW())")
    int insertFurniture(HyFurniture hyFurniture);

    // 删除家具
    @Delete("DELETE FROM hy_furniture WHERE id = #{id}")
    int deleteFurniture(Long id);

    // 更新家具信息
    @Update("UPDATE hy_furniture SET name = #{name}, description = #{description}, furnnum = #{furnnum}, price = #{price}, region_id = #{region_id}, " +
            "lease_price = #{lease_price}, material = #{material}, size = #{size}, manufacturer = #{manufacturer}, category_id = #{category_id}, updated_at = NOW() " +
            "WHERE id = #{id}")
    int updateFurniture(HyFurniture hyFurniture);

    // 查询所有家具
    @Select("SELECT * FROM hy_furniture")
    List<HyFurniture> getAllFurniture();

    // 根据家具ID查询家具
    @Select("SELECT * FROM hy_furniture WHERE id = #{id}")
    HyFurniture getFurnitureById(Long id);

    // 添加家具图片
    @Insert("INSERT INTO hy_furniture_image(furniture_id, url) VALUES(#{furnitureId}, #{url})")
    int insertFurnitureImage(HyFurnitureImage hyFurnitureImage);

    // 删除家具图片
    @Delete("DELETE FROM hy_furniture_image WHERE id = #{id}")
    int deleteFurnitureImage(Long id);

    // 根据家具ID查询图片
    @Select("SELECT * FROM hy_furniture_image WHERE furniture_id = #{furnitureId}")
    List<HyFurnitureImage> getFurnitureImagesByFurnitureId(Long furnitureId);

    // 根据分类ID查询家具
    @Select("SELECT * FROM hy_furniture WHERE category_id = #{categoryId}")
    List<HyFurniture> getFurnitureByCategoryId(Long categoryId);

    //根据区县id查询家具
    List<HyFurniture> findFurnitureByCategoryId(@Param("categoryId") Long categoryId);


    //根据家具id查询家具
    HyFurniture selectById (@Param("id") Long id);

    //查询所有家具信息
    List<HyFurniture> selectAll();

    // 更新库存数量
    int updatefurnnum(@Param("furnitureId") Long furnitureId,@Param("quantity") int quantity);


    long getTotalFurnitureCount();


    List<HyFurnitureWithImage> getFurnitureWithImages(@Param("offset") int offset,@Param("pageSize") int pageSize);

    HyFurniture selectHyFurnitureById(Long id);
}
